import request from '@/utils/request.js'

//注册接口
export const registerService = (RegisterData) => {
    return request.post('/user/register', RegisterData);
}

//登录
export const loginService = (LoginData) => {
    return request.post('/user/login', LoginData);
}

//显示当前登录用户的信息
export const showUserInfoService = () => {
    return request.get('/user');
}

//修改用户信息
export const updateUserInfoService = (UserInfoData) => {
    return request.put('/user', UserInfoData);
}

//上传头像
export const updateAvatarService = (avatarURL) => {
    const params = new URLSearchParams();
    //这里的键要跟后端传入的参数一致
    params.append('avatarURL', avatarURL);
    return request.patch('/user/updateAvatar', params);
}

//修改密码
export const updatePwdService = (pwdData) => {
    return request.patch('/user/updatePwd',
        {
            old_pwd: pwdData.oldPassword,
            new_pwd: pwdData.newPassword,
            re_pwd: pwdData.rePassword
        });
}